import GameFrameworkModule from "../Base/GameFrameworkModule";
import {ISettingManager} from "./ISettingManager";
import {ISettingHelper} from "./ISettingHelper";
import ccclass = cc._decorator.ccclass;
@ccclass("SettingManager")
export class SettingManager implements GameFrameworkModule,ISettingManager{
    private  _settingHelper:ISettingHelper;

    get Count(): number {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        return this._settingHelper.Count;
    }

    GetAllSettingNames(): string[] {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        return this._settingHelper.GetAllSettingNames();
    }

    GetBool(settingName: string): boolean {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        if (settingName == "" || settingName == undefined)
        {
            throw new Error("Setting name is invalid.");
        }

        return this._settingHelper.GetBool(settingName);
    }

    GetNumber(settingName: string): number {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        if (settingName == "" || settingName == undefined)
        {
            throw new Error("Setting name is invalid.");
        }

        return this._settingHelper.GetNumber(settingName);
    }

    GetObject(settingName: string): any {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        if (settingName == "" || settingName == undefined)
        {
            throw new Error("Setting name is invalid.");
        }
        return this._settingHelper.GetObject(settingName);
    }

    GetString(settingName: string): string {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        if (settingName == "" || settingName == undefined)
        {
            throw new Error("Setting name is invalid.");
        }
        return this._settingHelper.GetString(settingName);
    }

    HasSetting(settingName: string): boolean {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        if (settingName == "" || settingName == undefined)
        {
            throw new Error("Setting name is invalid.");
        }
        return this._settingHelper.HasSetting(settingName);
    }

    Load(): boolean {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }

        return this._settingHelper.Load();
    }

    get Priority(): number {
        return 950;
    }

    RemoveAllSettings(): void {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        this._settingHelper.RemoveAllSettings();
    }

    RemoveSetting(settingName: string): boolean {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        if (settingName == "" || settingName == undefined)
        {
            throw new Error("Setting name is invalid.");
        }
        return this._settingHelper.RemoveSetting(settingName);
    }

    Save(): boolean {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        return this._settingHelper.Save();
    }

    SetBool(settingName: string, value: boolean): void {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        if (settingName == "" || settingName == undefined)
        {
            throw new Error("Setting name is invalid.");
        }
        this._settingHelper.SetBool(settingName,value);
    }

    SetNumber(settingName: string, value: number): void {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        if (settingName == "" || settingName == undefined)
        {
            throw new Error("Setting name is invalid.");
        }
        this._settingHelper.SetNumber(settingName,value);
    }

    SetObject(settingName: string, obj: any): void {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        if (settingName == "" || settingName == undefined)
        {
            throw new Error("Setting name is invalid.");
        }
        this._settingHelper.SetObject(settingName,obj);
    }

    SetSettingHelper(settingHelper: ISettingHelper): void {
        if (settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }

        this._settingHelper = settingHelper;
    }

    SetString(settingName: string, value: string): void {
        if (this._settingHelper == null)
        {
            throw new Error("Setting helper is invalid.");
        }
        if (settingName == "" || settingName == undefined)
        {
            throw new Error("Setting name is invalid.");
        }
        this._settingHelper.SetString(settingName,value);
    }

    Shutdown(): void {
        this.Save();
    }

    Update(elapseSeconds: number, realElapseSeconds: number): void {
    }

    get baseName(): string {
        return "GameFrameworkModule";
    }

}